package com.lxp.modules.gyy.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxp.modules.gyy.domain.ProjectTask;
import com.lxp.modules.gyy.domain.vo.TaskParam;
import com.lxp.modules.gyy.mapper.ProjectTaskMapper;
import com.lxp.modules.gyy.service.ProjectTaskService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【project_task(Task)】的数据库操作Service实现
 * @createDate 2024-02-29 10:37:33
 */
@Service
public class ProjectTaskServiceImpl extends ServiceImpl<ProjectTaskMapper, ProjectTask> implements ProjectTaskService {

    @Override
    public List<ProjectTask> getList(TaskParam param) {
        Date startDate = param.getStartDate();
        Date endDate = param.getEndDate();
        if (startDate != null) {
            param.setStartDate(DateUtil.offsetHour(param.getStartDate(), -8));
        }
        if (endDate != null) {
            param.setEndDate(DateUtil.offsetHour(param.getEndDate(), 16));
        }
        return this.baseMapper.getList(param);
    }

    @Override
    public List<ProjectTask> getListByUserId(Integer userId, Date startDate, Date endDate) {
        TaskParam taskParam = new TaskParam();
        if (userId != null) {
            taskParam.setUserId(userId);
        }
        if (startDate == null && endDate == null) {
            Date date = DateUtil.beginOfMonth(new Date()).toJdkDate();
            Date jdkDate = DateUtil.offsetHour(date, -8).toJdkDate();
            taskParam.setStartDate(jdkDate);
        }
        if (startDate != null) {
            taskParam.setStartDate(DateUtil.offsetHour(startDate, -8));
        }
        if (endDate != null) {
            taskParam.setEndDate(DateUtil.offsetHour(endDate, 16));
        }
        return this.baseMapper.getList(taskParam);
    }
}




